import { PORT1 } from "@/api/config/servicePort";
import http from "@/api";
import { ReqPage, ResPage } from "@/api/interface";

// AI Chat 对话
export namespace Chat {
  export interface ResChat {
    id: number; //  主键
    userId: number; // 用户Id
    title: string; // 对话标题
    pinned: boolean; // 是否置顶
    pinnedTime: Date; // 置顶时间
    roleId: number; // 角色id
    knowledgeId: number; // 知识库id
    modelId: number; // 模型id
    systemMessage: string; // 角色设定
    temperature: number; // 温度参数
    maxTokens: number; // 单条回复的最大 Token 数量
    maxContexts: number; // 上下文的最大 Message 数量
    createBy: number;
    createTime: string;
    updateBy: number;
    updateTime: Date;
    isDeleted: number;
    // 额外字段
    roleAvatar?: string; // 角色头像
    modelName?: string; // 模型名字
  }

  export interface ReqChat extends ReqPage {
    id: number; //  主键
    userId: number; // 用户Id
    title: string; // 对话标题
    pinned: boolean; // 是否置顶
    pinnedTime: Date; // 置顶时间
    roleId: number; // 角色id
    knowledgeId: number; // 知识库id
    modelId: number; // 模型id
    systemMessage: string; // 角色设定
    temperature: number; // 温度参数
    maxTokens: number; // 单条回复的最大 Token 数量
    maxContexts: number; // 上下文的最大 Message 数量
    createBy: number;
    createTime: Date;
    updateBy: number;
    updateTime: Date;
    isDeleted: number;
  }
}
export const deleteChatMyByUnpinned = () => {
  return http.delete<Boolean>(PORT1 + `/ai/chat/delete-by-unpinned`);
};
/**
 * 查询我的聊天对话
 */
export const getChatMyList = () => {
  return http.get<Chat.ResChat[]>(PORT1 + `/ai/chat/my-list`);
};

// 创建【我的】聊天对话
export const createChatMy = (data: Chat.ReqChat) => {
  return http.post<number>(PORT1 + `/ai/chat/create-my`, data);
};
// 查询AI Chat 对话分页
export const getChatPage = (params: Chat.ReqChat) => {
  return http.get<ResPage<Chat.ReqChat>>(PORT1 + `/ai/chat/page`, params);
};
// 查询AI Chat 对话详情
export const getChat = (id: number) => {
  return http.get<Chat.ReqChat>(PORT1 + `/ai/chat/get/${id}`);
};

// 新增AI Chat 对话
export const createChat = (data: Chat.ReqChat) => {
  return http.post<Boolean>(PORT1 + `/ai/chat/create`, data);
};

// 修改AI Chat 对话
export const updateChat = (data: Chat.ReqChat) => {
  return http.put<Boolean>(PORT1 + `/ai/chat/update`, data);
};
// 删除AI Chat 对话
export const deleteChat = (id: number) => {
  return http.delete<Boolean>(PORT1 + `/ai/chat/delete/${id}`);
};
